import { ref } from 'vue'

interface SoundSettings {
  enabled: boolean
  volume: number
  moveSound: boolean
  captureSound: boolean
  checkSound: boolean
  gameEndSound: boolean
}

export function useChessSoundSettings() {
  const settings = ref<SoundSettings>({
    enabled: true,
    volume: 0.5,
    moveSound: true,
    captureSound: true,
    checkSound: true,
    gameEndSound: true
  })

  const loadSettings = () => {
    const savedSettings = localStorage.getItem('chessSettings')
    if (savedSettings) {
      settings.value = JSON.parse(savedSettings)
    }
  }

  const saveSettings = () => {
    localStorage.setItem('chessSettings', JSON.stringify(settings.value))
  }

  const updateSettings = (newSettings: Partial<SoundSettings>) => {
    settings.value = { ...settings.value, ...newSettings }
    saveSettings()
  }

  const toggleSound = (type: keyof SoundSettings) => {
    if (typeof settings.value[type] === 'boolean') {
      settings.value = {
        ...settings.value,
        [type]: !settings.value[type]
      }
      saveSettings()
    }
  }

  const setVolume = (volume: number) => {
    settings.value.volume = Math.max(0, Math.min(1, volume))
    saveSettings()
  }

  return {
    settings,
    loadSettings,
    updateSettings,
    toggleSound,
    setVolume
  }
} 